package com.bharatonjava.swift.dao;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.bharatonjava.swift.dao.mappers.EnumerationRowMapper;
import com.bharatonjava.swift.domain.Enumeration;

@Repository
public class EnumerationsDao implements IEnumerationsDao{
	
	private JdbcTemplate jdbcTemplate;

	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	@Override
	public List<Enumeration> getEnumerationsByGroup(String enumGroup) {
		String sql = "SELECT ENUM_ID, ENUM_GROUP, ENUM_VALUE FROM ENUMERATIONS WHERE UPPER(ENUM_GROUP) = UPPER(?)";
		List<Enumeration> enums = (List<Enumeration>) this.jdbcTemplate.query(sql, new Object[]{enumGroup},new EnumerationRowMapper());
		return enums;
	}
	
	@Override
	public Enumeration getEnumerationByValue(String enumValue){
		String sql = "SELECT ENUM_ID, ENUM_GROUP, ENUM_VALUE FROM ENUMERATIONS WHERE UPPER(ENUM_VALUE) = UPPER(?)";
		Enumeration enumeration = (Enumeration) this.jdbcTemplate.queryForObject(sql, new Object[]{enumValue},new EnumerationRowMapper());
		return enumeration;
	}

}
